# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=cmake
pkgver=3.30.5
pkgrel=0
pkgdesc="Cross-platform, open-source make system"
url="https://www.cmake.org/"
arch="all"
license="BSD-3-Clause"
makedepends="
	bzip2-dev
	expat-dev
	libarchive-dev
	libuv-dev
	linux-headers
	ncurses-dev
	py3-sphinx
	rhash-dev
	samurai
	xz-dev
	zlib-dev
	"
checkdepends="file"
subpackages="
	ccmake
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-emacs::noarch
	$pkgname-vim::noarch
	"
case $pkgver in
*.*.*.*) _v=v${pkgver%.*.*};;
*.*.*) _v=v${pkgver%.*};;
esac
source="https://www.cmake.org/files/$_v/cmake-$pkgver.tar.gz"
options="!check"

build() {
	# jsoncpp/cppdap/curl/nghttp2 needs cmake to build so to avoid recursive build
	# dependency, we use the bundled version.
	# Do NOT remove --no-system-*

	./bootstrap \
		--prefix=/usr \
		--mandir=/share/man \
		--datadir=/share/$pkgname \
		--docdir=/share/doc/$pkgname \
		--sphinx-man \
		--no-system-cppdap \
		--no-system-curl \
		--no-system-jsoncpp \
		--no-system-nghttp2 \
		--system-bzip2 \
		--system-expat \
		--system-libarchive \
		--system-liblzma \
		--system-librhash \
		--system-libuv \
		--system-zlib \
		--generator=Ninja \
		--parallel="${JOBS:-2}"
	ninja
}

check() {
	bin/ctest
}

package() {
	DESTDIR="$pkgdir" ninja install
}

ccmake() {
	pkgdesc="$pkgdesc (ccmake configurator)"

	amove usr/bin/ccmake
}

emacs() {
	pkgdesc="$pkgdesc (emacs mode)"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"

	amove usr/share/emacs
}

vim() {
	pkgdesc="$pkgdesc (vim files)"
	install_if="$pkgname=$pkgver-r$pkgrel vim"

	amove usr/share/vim
}

sha512sums="
968ad4769e869378049b1d82ace98db25a6cb234b6362a51737f0d2978b8914ad42967ba112741850b23631e73b8a8876cd4f99dd0285b9da1c2bb5ea4c4ee4e  cmake-3.30.5.tar.gz
"
